package com.person.leetcode.editor.cn;

/**
  * 面试题 17.11.单词距离
  * 2022-05-27 09:28:18
**/
public class Sequence_面试题_17_11_FindClosestLcci {
    public static void main(String[] args) {
        Solution solution = new Sequence_面试题_17_11_FindClosestLcci().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
//太简单了吧
class Solution {
    public int findClosest(String[] words, String word1, String word2) {
        int  a = -1,b = -1,ans = words.length;
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if (word.equals(word1)){
                a  = i;
            }else if (word.equals(word2)){
                b = i;
            }
            if ( -1 != a && - 1 != b){
                ans = Math.min(Math.abs(a-b), ans);
            }
        }
        return ans;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
